import { BasicColumn, FormSchema } from '/@/components/Table';
import { render } from '/@/utils/common/renderUtils';
import { DataGroupBizType } from "/@/components/BizDataGroup/index"
import { listDataGroupTree } from '/@/api/infra/dataGroup';

const getStatus = (text) => {
  const color = text == '1' ? 'green' : text == '0' || text == '2' ? 'red': 'gray';
  return render.renderTag(render.renderDict(text, 'short_link_status'), color)
}

export const columns: BasicColumn[] = [
  {
    title: 'id',
    dataIndex: 'id',
    width: 150,
    defaultHidden: true
  },

  {
    title: '短链',
    dataIndex: 'code',
    slots: { customRender: 'shortUrl' },
    width: 90,
  },

  {
    title: '组名',
    dataIndex: 'groupName',
    width: 100,
  },

  {
    title: '访问IP',
    dataIndex: 'ip',
    width: 120,
  },

  {
    title: '访问地址',
    dataIndex: 'address',
    width: 150,
    customRender: ({ text }) => {
      return text ? text : '-'
    },
  },

  {
    title: '操作系统',
    dataIndex: 'os',
    width: 110,
  },

  {
    title: '浏览器',
    dataIndex: 'browser',
    width: 110,
  },


  {
    title: '访问时间',
    dataIndex: 'createdAt',
    width: 150,
  }
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'code',
    label: '短链码',
    component: 'Input',
  },
  {
    field: 'groupId',
    label: '短链组',
    component: 'ApiSelect',
    componentProps: ({ formActionType }) => {
      return {
        optionFilterProp: "label",
        showSearch: true,
        labelField: 'name',
        valueField: 'id',
        params: {
          bizType: DataGroupBizType.SHORT_LINK,
        },
        api: listDataGroupTree,
      }
    }
  }
];
